<template>
	<view class="pjsp">
		<view class="p-30 bg-fff mt-15">
			<view class="c-333 f-26 mb-10">
				商品信息
			</view>
			<view class="f2 flex0-start">
				<view class="f2-1 mr-30">
					<image v-cloak :src="lisData2.goods_image_url" mode=""></image>
				</view>
				<view class="flex0-start f2-2 w100 flex-bt">
					
					<view class="">
						<view class="c-333 f-24">
							{{lisData2.goods_name}}
						</view>
						<view class="f-26 c-zt">
							￥{{lisData2.goods_price}}
						</view> 
						<view class="f-24">
							{{lisData2.goods_spec_name||''}}
						</view>
					</view>
					
				</view>
			</view>
			<view class="flex0">
				<text class="c-333 pfe">商品评分</text>
				<!-- 自定义星星大小 -->
				<uni-rate @change="cgval" size="24" :value="pfval1"></uni-rate>
			</view>
		</view>
		<view class="p-30 bg-fff mt-15 f3">
			<view class="">
				<textarea class="c-333 f-24" v-model="textValue" value="" placeholder="商品质量如何，快来写下你的评价吧~" />
			</view>
			<view class="sctp">
				<image @click="upload(1)" :src="img1 ? img1 : `${picUrl}/w/pt.png`" mode=""></image>
				<image @click="upload(2)" :src="img2 ? img2 : `${picUrl}/w/pt.png`" mode=""></image>
				<image @click="upload(3)" :src="img3 ? img3 : `${picUrl}/w/pt.png`" mode=""></image>
			</view>
			<view class="f-24">
				（图片上传最多3张）
			</view>
		</view>
		<view class="xjipf bg-fff mt-15 p-30">
			<view class="c-333">
				星级评分
			</view>
			<view class="flex0">
				<text class="mr-90 f-26 c-333">物流服务</text>
				<!-- 自定义星星大小 -->
				<uni-rate @change="cgval1" size="24" :value="pfval2"></uni-rate>
			</view>
			<view class="flex0">
				<text class="mr-90 f-26 c-333">客服服务</text>
				<!-- 自定义星星大小 -->
				<uni-rate @change="cgval2" size="24" :value="pfval3"></uni-rate>
			</view>
			<view class="flex0">
				<text class="mr-90 f-26 c-333">商品质量</text>
				<!-- 自定义星星大小 -->
				<uni-rate @change="cgval3" size="24" :value="pfval4"></uni-rate>
			</view>
		</view>
		<!-- <view @click="ok()" class="m-30 fbpl center">
			<text class="bg-zt ">
				发表评论
			</text>
		</view> -->
		<view @click="ok()" class="submitBtn">
			发表评论
		</view>
	</view>
</template>

<script>
	const requImg = require("@/common/api_sign/requImg.js")
	import uniRate from '@/components/uni-rate/uni-rate.vue'
	export default {
		data() {
			return {
				textValue:"",
				lisData:[],
				lisData2:{},
				pfval1:5,
				pfval2:0,
				pfval3:0,
				pfval4:0,
				img1:"",
				img2:"",
				img3:"",
				ImgInfo1:"",
				ImgInfo2:"",
				ImgInfo3:"",
				orderData:"",
				goods_id:0,
				order_id:0,
				Imgdata:"",
				isData:true,
				store_desccredit:"",
				store_servicecredit:"",
				store_deliverycredit:"",
				Disable:false
			}
		},
		//h写片段
		onLoad(options) {
			this.goods_id=options.goods_id;
			this.order_id=options.order_id;
			this.getLis()
			// this.goods_id=uni.getStorageSync('goods_id');
			// console.log(this.goods_id)
			// this.upload(i)
		},
		
		methods: {
			ok(){
				if(this.Disable){
					return false;
				}
				this.Disable=true
				let evaluate_image="";
				if(this.ImgInfo1 && this.ImgInfo1!=`${this.picUrl}/w/pt.png`){
					evaluate_image+=this.ImgInfo1+","
				}
				if(this.ImgInfo2 && this.ImgInfo2!=`${this.picUrl}/w/pt.png`){
					evaluate_image+=this.ImgInfo2+","
				}
				if(this.ImgInfo3 && this.ImgInfo3!=`${this.picUrl}/w/pt.png`){
					evaluate_image+=this.ImgInfo3+","
				}
				evaluate_image=evaluate_image.slice(0,evaluate_image.length-1)
				console.log(evaluate_image)
				var that=this;
				this.$util.request({//提交评论
					url: '/mobile/index.php?act=member_evaluate&op=add_evaluate',
					method: 'POST',
					data: {
						order_id:this.order_id,
						goods_id:this.goods_id,
						evaluate_score:this.pfval1,
						evaluate_comment:this.textValue,
						evaluate_image:evaluate_image,
						store_desccredit:this.store_desccredit,
						store_servicecredit:this.store_servicecredit,
						store_deliverycredit:this.store_deliverycredit
					},
				}).then(function(res) {
					that.Disable=false
					if(res.error_code==0){
						uni.showToast({
							title:"评价成功！"
						})
						setTimeout(()=>{
							uni.redirectTo({
								url:"/member/order/AllOrder"
							})
							// uni.navigateTo({
							// 	url:"../newpage/pinlunlis"
							// })
						},1500)
					}else if(res.message.indexOf("接口签名验证失败")!=-1){
						uni.showToast({
							title:"非法字符",
							icon:"none"
						})	
					}else{						
						uni.showToast({
							title:res.message,
							icon:"none"
						})			
					}						
				})
			},
			getLis(){
				// console.log('order_id='+this.order_id,'goods_id='+this.goods_id)
				var that=this;
				this.$util.request({
					url: '/mobile/index.php?act=member_order&op=show_order',
					method: 'get',
					data: {
						"order_id":this.order_id,
						"goods_id":this.goods_id
					},
				}).then((res)=> {
					this.lisData=res.datas
					for(let i=0;i<this.lisData.order_info.goods_list.length;i++){
						if(Number(this.goods_id) == Number(this.lisData.order_info.goods_list[i].goods_id)){
							this.lisData2=res.datas.order_info.goods_list[i]
						}
					}							
				})
			},
		
			upload(i){
				let that = this;
				if(that.isData){
					uni.chooseImage({//图片选择上传
					count: 1,
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album','camera'], //从相册选择
					success: (res)=> {
										const tempFilePaths = res.tempFilePaths;
										let  data = requImg.request("index.php?act=upload&op=uploadFile&buss_type="+that.$uploadType.uploadtype013);
									 var uper = uni.uploadFile({
									  url:that.$apiurl+"index.php?act=upload&op=uploadFile",
									  filePath:tempFilePaths[0],
									  name: 'file',
									  formData: {
										key:data.key,
										api_sign:data.api_sign,
										buss_type:data.buss_type,
										comefrom:data.comefrom,
										api_time:data.api_time,
										// api_member_id:data.api_member_id,
										// api_member_name:data.api_member_name,
									 },
									  success(res1) {
										  
										  let ImgInfo=JSON.parse(res1.data)
										  if(ImgInfo.error_code!=0){
											  uni.showToast({
												title:ImgInfo.message,
												icon:"none"
											  }) 
											  return false
										  }
										  
										  that.Imgdata={"filePath":ImgInfo.datas.file_url,"path":ImgInfo.datas.file_name};
										  console.log('that.Imgdata',that.Imgdata)
										  if(i==1){
										
												if(that.Imgdata.filePath){
													that.img1=that.Imgdata.filePath;
													that.ImgInfo1=that.Imgdata.path;
												}else{
													uni.showToast({
														title:"图片上失败",
														icon:"none"
													})
												}
													
										  }else if(i==2){
										  
												if(that.Imgdata.filePath){
													that.img2=that.Imgdata.filePath;
													that.ImgInfo2=that.Imgdata.path;
												}else{
													uni.showToast({
														title:"图片上失败",
														icon:"none"
													})
												}
													
										  }else if(i==3){
										  
												if(that.Imgdata.filePath){
													that.img3=that.Imgdata.filePath;
													that.ImgInfo3=that.Imgdata.path;
												}else{
													uni.showToast({
														title:"图片上失败",
														icon:"none"
													})
												}
										  }
									  },
									  })
							 }, fail(e) {
								console.log(e)
							 }
							});
		}else{
			uni.showToast({
				title:"图片正在上传中",
				icon:"loading"
			})
		}
		  
	},
			
			
			cgval(e){
				this.pfval1=e.value
			},
			cgval1(e){
				this.store_desccredit=e.value;
			},
			cgval2(e){
				this.store_servicecredit=e.value;
			},
			cgval3(e){
				this.store_deliverycredit=e.value;
			},
			
		},
		components: {uniRate}
	}
</script>

<style>
	.pjsp .fbpl text{
		display: inline-block;
		padding:30upx 70upx;
		color:#fff;
		border-radius: 50upx;
		/* margin:0 auto; */
	}
	.pjsp .xjipf>view{
		margin-bottom:30upx;
	}
	.pjsp .sctp image{
		width:161upx;
		height:161upx;
		margin-right:20upx;
	}
	.pjsp  .pfe{
		margin-right:90upx;
	}
	.mr-90{
		margin-right:90upx;
	}
	.pjsp .f2 .shuli{
		margin-top:65upx;
	}
	.pjsp .f2 .f2-1 image{
		width:173upx;
		height:173upx;
	}
	.pjsp .f2 .f2-2>view:first-of-type>view:first-of-type{
		width:445upx;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;
		height:80upx;
	}
	.submitBtn{
		height: 80upx;
		line-height: 80upx;
		text-align: center;
		padding: 0 60upx;
		color: #FFFFFF;
		background-color: #ff4300;
		font-size: 30upx;
		width: 200upx;
		margin: 100upx auto;
		border-radius: 40upx;
	}
</style>
